/**
 * Created by Administrator on 2017/5/10 0010.
 */
import React from "react";
import Creatorder_StepThree from "./Createorder_StepThree";
import ReactKey from "../../../util/ReactKey"
export default class CreatOrderTwo extends React.Component{
    constructor(props){
        super(props);
        this.state={
            goodsremark: [],
        }
        this.goodsremark = [{}, {}, {}];
    }

    componentWillMount(){
        if(this.props.fromEdit== "edit"||this.props.fromEdit == "modify"){
            let goodsremark =this.props.goodsremark;
            if(goodsremark && goodsremark.length>=1){
                this.setState({
                    goodsremark: goodsremark||[{}, {}, {}],
                });
                this.goodsremark = goodsremark||[{}, {}, {}];
            }else {
                this.setState({
                    goodsremark:[{}, {}, {}],
                });
                this.goodsremark = [{}, {}, {}];
            }

        }else {
            this.setState({
                goodsremark: [{}, {}, {}],
            })
        }

        /*this.setState({
            goodsremark: this.goodsremark
        });*/
    }
    componentWillUnmount(){
        /*console.log(123);
        this.goodsremark = [{}, {}, {}];
        this.setState({
            goodsremark: [{}, {}, {}],
        });*/
    }
    addremarkitemlist() {
        let goodsremark = this.state.goodsremark;
        goodsremark.push({});
        this.setState({
            goodsremark: goodsremark
        });

    }

    deremarkteitem(index) {
        let goodsremark = this.state.goodsremark;
        goodsremark.splice(index, 1);
        this.setState({
            goodsremark: goodsremark
        });
    }
    


    addStepThree() {
        return this.state.goodsremark.map((context, index)=> {
            return (
                <Creatorder_StepThree key={ReactKey.key} index={index} context={context}
                                      order_type={this.props.order_type}
                                      addremarkitemlist={this.addremarkitemlist.bind(this)}
                                      deremarkteitem={this.deremarkteitem.bind(this)}
                                      totallenght={this.state.goodsremark.length}
                />
            );
        });
    }


    render(){
        return (
            <div style={{width:'100%'}}>
                {/*<p className="create_order_step">*/}
                    {/*第二步：添加交货要求*/}
                    {/*<span className="create_order_step_line"/>*/}
                {/*</p>*/}

                <table className="order_form_table">
                    <thead>
                    <tr className="order_from_tr">
                        <td className="order_frorm_td order_frorm_td_three_time order_detail_thead_style">交货时间</td>
                        <td className="order_frorm_td order_frorm_td_three_num order_detail_thead_style">数量</td>
                        <td className="order_frorm_td order_frorm_td_three_remark order_detail_thead_style">备注</td>
                        <td className="order_frorm_td order_frorm_td_three_adddetel order_detail_thead_style"/>
                    </tr>
                    </thead>
                    {
                        this.addStepThree()
                    }
                </table>
            </div>
        )
    }
}